package com.falcon.file.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@Getter
public enum FileTypeEnum {

    UNKNOWN(0,"未知类型", Collections.emptyList()),

    TXT(1,"文本文件",Arrays.asList("txt" )),

    WORD(2,"word",Arrays.asList("doc", "docx" )),

    EXCEL(3,"excel",Arrays.asList("xls", "xlsx" )),

    PPT(4,"ppt",Arrays.asList("ppt", "pptx" )),

    PDF(5,"pdf",Arrays.asList("pdf" )),

    HTML(6,"html",Arrays.asList("html", "htm" )),

    FLASH(7,"flush",Arrays.asList("swf", "flv" )),

    VIDEO(8,"视频",Arrays.asList("mp4", "avi", "rmvb" )),

    IMAGE(9,"图片",Arrays.asList("bmp", "gif", "jpg", "jpeg", "png" )),

    ;

    private int code;

    private String desc;

    private List<String> extensions;

    FileTypeEnum(int code, String desc, List<String> extensions) {
        this.code = code;
        this.desc = desc;
        this.extensions = extensions;
    }

    public static FileTypeEnum OfExtension(String extension) {
        return Arrays.stream(FileTypeEnum.values())
                .filter(typeEnum -> typeEnum.getExtensions().contains(extension))
                .findAny().orElseGet(() -> UNKNOWN);
    }


}

